package servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.User;
import dao.UserDao;

/**
 * 这是一个处理显示用户列表的Servlet,本Servlet调用UserDao获取用户数据对象集合，
 * 并将数据集合存储到request对象中，再跳转到users.jsp页面，在users.jsp页面用EL和JSTL将数据取出并展示在表格中。
 * 本项目中这个功能限于管理员用户使用，所以在登录页面用管理员身份登录即可看到此菜单。
 * @author Steven Suo
 *
 */
@WebServlet("/userList.view")
public class UserListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		UserDao userAction = new UserDao();
    	List<User> users = userAction.findAll();
    	request.setAttribute("userList", users);
    	request.getRequestDispatcher("users.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
